package com.example.project;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;

public class Options_Activity extends Activity implements OnClickListener{
	Button btn_OK;
	RadioButton rad_Easy, rad_Medium, rad_Hard;
	int Diff_option, Return_diff_option;
	Bundle extra_values;
	// Hàm khởi tạo cho các biến Button
	private void Initial_Function()
	{
		btn_OK=(Button)findViewById(R.id.btn_ok);
		rad_Easy=(RadioButton)findViewById(R.id.rad_easy);
		rad_Medium=(RadioButton)findViewById(R.id.rad_medium);
		rad_Hard=(RadioButton)findViewById(R.id.rad_hard);
		extra_values=getIntent().getExtras();
		if(extra_values!=null)
		{
			Diff_option=extra_values.getInt("Diff_Option");
		}
		if(Diff_option==0)
			rad_Easy.setChecked(true);
		else if(Diff_option==1)
			rad_Medium.setChecked(true);
		else if(Diff_option==2)
			rad_Hard.setChecked(true);
	}
	
	private int Check_difficulty_option()
	{
		if(rad_Easy.isChecked())
			Return_diff_option=0;
		else if(rad_Medium.isChecked())
			Return_diff_option=1;
		else if(rad_Hard.isChecked())
			Return_diff_option=2;
		return Return_diff_option;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_options);
		Initial_Function();				
		
		btn_OK.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
		case R.id.btn_ok:
			Intent Return_option = new Intent();
			Return_option.putExtra("Return_Diff_Option", Check_difficulty_option());
			setResult(Activity.RESULT_OK, Return_option);
			finish();
			break;
		}
	}
}
